package com.whsxt.servlet;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import com.whsxt.common.Constant;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author 武汉尚学堂
 */
@WebServlet("/verCode.do")
public class VerCodeServlet  extends HttpServlet {


    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //验证码信息对象
        LineCaptcha captcha = CaptchaUtil.createLineCaptcha(200, 38, 4, 10);
        String code = captcha.getCode();//获取具体的验证码
        //将验证码放入到session中
        req.getSession().setAttribute(Constant.VERCODE_KEY,code);
        //将验证码输出
        captcha.write(resp.getOutputStream());
    }
}
